home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11343 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What happens on realloc() failure?
  5. Date: 22 Mar 1996 18:25:54 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ivnfiINNdib@keats.ugrad.cs.ubc.ca>
  8. References: <Pine.SOL.3.91-941213.960322192958.24127A-100000@aidan.ncl.ac.uk>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <Pine.SOL.3.91-941213.960322192958.24127A-100000@aidan.ncl.ac.uk>,
  12. Tom Seddon  <T.W.Seddon@ncl.ac.uk> wrote:
  13.  >I am writing a program which will need to call realloc() a fair amount. 
  14.  >What I would like to know is whether the original data is still usable if
  15.  >the realloc() fails. (Although it is unlikely that there will be problems
  16.  >with running out of memory, it is possible that there will be problems due
  17.  >to fragmentation of memory.)
  18.  
  19. Read some reliable documentation (ISO standard, K&R2). If you had the K&R, you
  20. would know from page 252 that:
  21.  
  22.     realloc returns a pointer to the new space, or NULL if the
  23.     request cannot be satisfied in which case [the pointer parameter]
  24.     is not changed.
  25.  
  26.  >Since realloc() returns NULL on failure, is it safe to use the pointer to 
  27.  >the malloc()ed area I was trying to resize?
  28.  
  29. Apparently so.
  30.  
  31.  >Or will the old area have 
  32.  >been freed by free() and now be unusable? What does the ANSI standard 
  33.  >have to say about this? I've never seen anything about this point before 
  34.  
  35. Presumably what I just said, since the K&R2 is quite faithful to the standard.
  36. -- 
  37.  
  38.